// component/drawer/drawer.js
var app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      value: true,
      observer: function (newVal, oladVal) {
        if (newVal == true) {
          this.show();
        } else {
          this.hide();
        }
      }
    },
    popHeight: {
      type: Number,
      value: 667,
      observer: function (newVal, oladVal) {
        if (newVal) {
          this.setData({
            drawerHeight: newVal
          })
        }
      }
    },
    popWidth: {
      type: Number,
      value: 375,
      observer: function (newVal, oladVal) {
        if (newVal) {
          this.setData({
            drawerWidth: newVal
          })
        }
      }
    },
    slideDirection: {
      type: String,
      value: 'bottom'
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    drawerHeight: app.globalData.pageHeightPx,
    drawerWidth: app.globalData.pageWidth,
    is_show: false,
    cover_show: false,
    drawer_show: false,
  },

  ready: function () {
    if (this.data.show == true) {
      this.show();
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    show: function () {
      this.setData({
        is_show: true,
      });
      setTimeout(() => {
        this.setData({
          drawer_show: true,
          cover_show: true
        });
      }, 100);
    },
    hide: function () {
      this.setData({
        drawer_show: false,
        cover_show: false,
      });

      //触发上级取消购买时间
      setTimeout(() => {
        this.setData({
          is_show: false,
        })
        this.triggerEvent('cancel', {}, {})
      }, 350);
    },
  }
})
